package com.vanzo.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.vanzo.encryption.R;
import com.vanzo.talkie.Follower;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tisen on 2018/3/8.
 */

public class BindNFCAdapter extends RecyclerView.Adapter<BindNFCAdapter.BindOne> {


    private List<Follower> followers = new ArrayList<>();

    @Override
    public BindOne onCreateViewHolder(ViewGroup parent, int viewType) {
        return new BindOne(LayoutInflater.from(parent.getContext()).inflate(R.layout.follower_item, parent, false));
    }

    @Override
    public void onBindViewHolder(BindOne holder, int position) {
        holder.setFollower(followers.get(position));
    }

    public void refresh(List<Follower> followers) {
        this.followers = followers;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return followers.size();
    }

    public class BindOne extends RecyclerView.ViewHolder {
        TextView terminal;
        TextView group;
        TextView channel;
        TextView lock;

        public BindOne(View itemView) {
            super(itemView);
            terminal = (TextView) itemView.findViewById(R.id.follower_item_terminal);
            group = (TextView) itemView.findViewById(R.id.follower_item_group);
            channel = (TextView) itemView.findViewById(R.id.follower_item_channel);
            lock = (TextView) itemView.findViewById(R.id.follower_item_lock);
        }

        public void setFollower(Follower follower) {
            terminal.setText("终端号：" + follower.getTerminalId() + "");
            group.setText("组号：" + follower.getGroupId() + "");
            channel.setText("频道号：" + follower.getChannelId() + "");
            lock.setText("锁定:" + follower.getIsLocked() + "");
        }
    }
}
